package olSystem;

import com.spm.pojo.CourseForCjw;
import com.spm.utils.CFWMapperUtil;

import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class StudentInfoServlets
 */

@WebServlet(name = "/StuInfoServlet",value = "/stu")
public class StuInfoServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public StuInfoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        process(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        process(req, resp);
    }

    protected void process(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("UTF-8");
//        try {
//
//            Connection conn = (new DBOper()).getConnection();
//            Statement statement =  conn.createStatement();
            String numSession =  req.getSession().getAttribute("numSession").toString();
//            String sql1 = "select Cno from usst.student_r_course where Sid = " + numSession;
//            String sql11="select * from usst.course where Cno = "+ sql1;
//            String sql1 = "select * from student where Sno = '" + numSession+ "'";
//            ResultSet resultSet = statement.executeQuery(sql1);
//
//            List<Student> courseStudentList = new ArrayList<Student>();
//            String ss="";
//            while (resultSet.next()) {
//                Student student = new Student();
//                ss=resultSet.getString("Sscourse");
//                student.setSelectedCourse(ss);
//                //student.setScore(resultSet.getString("Score"));
//                //将学生加入到课程列表
//                courseStudentList.add(student);
//            }
//
//
//
//            String courseStudentString= courseStudentList.get(0).getSelectedCourse();
//            String[] array = courseStudentString.split(",");
        CFWMapperUtil cfwMapperUtil = new CFWMapperUtil();
        List<CourseForCjw> studentCourseList = cfwMapperUtil.selectCourseForCjwListBySid(numSession);
//        System.out.println("===========================STUINFO======================");
//        System.out.println(numSession);
//        for (CourseForCjw c: studentCourseList
//             ) {
//            System.out.println(c);
//        }
//        System.out.println("===========================STUINFO======================");

        //for (String s:array) {
//                String sql2 = "select * from course where Cno = " + s ;
//                String sq = "select Tid from teacher_r_course where Cno = " + s ;
//                String sql3="select * from teacher where Tid =" +sq;
//            String sql2 = "select * from course where Cname = '" +ss + "'";
//            ResultSet   resultSet1 = statement.executeQuery(sql2);
//
//                while (resultSet1.next()) {
//                    Course course = new Course();
//                    course.setCourseId(resultSet1.getInt("Cno"));
//                    course.setCourseName(resultSet1.getString("Cname"));
//                    course.setCoursePlace(resultSet1.getString("Cposition"));
//                    course.setCourseTime(resultSet1.getString("Cstarttime"));
//                    course.setCourseTeacher(resultSet1.getString("Cteacher"));
//                    course.setCourseTimelength(resultSet1.getString("Clengthtime"));
//                    //将课程加入学生课程列表
//                    studentCourseList.add(course);
//                }
//                resultSet = statement.executeQuery(sql3);
//                while (resultSet.next()){
//                    course.setCourseTeacher(resultSet.getString("Tname"));
//                    studentCourseList.add(course);
//                }
           // }

            req.setAttribute("studentCourseList", studentCourseList);
            //req.setAttribute("courseStudentList",courseStudentList);
//
//            resultSet.close();
//            statement.close();
//            conn.close();

//        } catch (Exception e) {
//            e.printStackTrace();
//        }

        resp.setCharacterEncoding("UTF-8");
        req.getRequestDispatcher("/Olsystem/selectcheck.jsp").forward(req, resp);
    }

}